package com.kws.commercial.controller;

import com.github.pagehelper.PageInfo;
import com.kws.commercial.dao.Info.QueryContractTemplatePageInfo;
import com.kws.commercial.dao.Rq.CreateContractTemplateRq;
import com.kws.commercial.dao.Rq.QueryContractTemplatePageRq;
import com.kws.commercial.dao.Rq.UpdateContractTemplateRq;
import com.kws.commercial.service.ContractTemplateService;
import com.kws.common.core.domain.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * <b>ContractTemplateController</b>
 *
 * @description: ContractTemplateController <br>
 * @date: 2024/10/23 16:55 <br>
 * @author: lhm <br>
 * @version: 1.0 <br>
 */

@Api(tags = "合同模板模块")
@RestController
public class ContractTemplateController {
    private static final Logger logger = LoggerFactory.getLogger(ContractTemplateController.class);


    @Autowired
    private ContractTemplateService contractTemplateService;

    @ApiOperation("分页查询合同模板")
    @PostMapping("/query/contractTemplate/page")
    public R<PageInfo<QueryContractTemplatePageInfo>> queryContractTemplatePage(@RequestBody QueryContractTemplatePageRq rq){
        PageInfo<QueryContractTemplatePageInfo> pageInfo = contractTemplateService.queryContractTemplatePage(rq);
        return R.ok(pageInfo);
    }

    @ApiOperation("新建合同模板")
    @PostMapping("/create/contractTemplate")
    public R createContractTemplate(@RequestBody CreateContractTemplateRq rq){
        boolean status = contractTemplateService.createContractTemplate(rq);
        return R.ok(status);
    }

    @ApiOperation("根据模板ID查询")
    @GetMapping("/query/contractTemplate/byId")
    public R queryContractTemplateById(@RequestParam Long id){
        QueryContractTemplatePageInfo info =  contractTemplateService.queryContractTemplateById(id);
        return R.ok(info);
    }

    @ApiOperation("根据模板ID修改模板内容")
    @PostMapping("/update/contractTemplate")
    public R updateContractTemplate(@RequestBody UpdateContractTemplateRq rq){
        boolean status = contractTemplateService.updateContractTemplate(rq);
        return R.ok(status);
    }

    @ApiOperation("根据模板ID删除模板")
    @GetMapping("/delete/contractTemplate/byId")
    private R deleteContractTemplateById(@RequestParam Long id){
        boolean status = contractTemplateService.deleteContractTemplateById(id);
        return R.ok(status);
    }

    @ApiOperation("上传合同")
    @PostMapping("/upload/contractTemplate")
    public R<String> uploadContractTemplate(@RequestParam("file") MultipartFile file){
        String fileUrl = contractTemplateService.uploadContractTemplate(file);
        return R.ok(fileUrl);
    }
}
